package edu.jhu.cs.oose.scheduleit.util;

import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * The utility class wrapping date elements
 * @author oose_group2
 *
 */
public class DateWrapper {

	/**
	 * The year element
	 */
	int year;
	/**
	 * The month element
	 */
	int month;
	/**
	 * The date element
	 */
	int date;
	/**
	 * The hour element
	 */
	int hrs;
	/**
	 * The minute element
	 */
	int min;
	/**
	 * The second element
	 */
	int sec;
	/**
	 * Whether it's set by calendar
	 */
	boolean setByCalendar;
	
	/**
	 * The constructor of DateWrapper class
	 * @param year	The year element
	 * @param month	The month element
	 * @param date	The date element
	 * @param hrs	The hour element
	 * @param min	The minute element
	 * @param sec	The second element
	 */
	public DateWrapper(int year, int month, int date, int hrs, int min, int sec) {
		super();
		this.year = year < 2000? year +1900:year;
		this.month = month;
		this.date = date;
		this.hrs = hrs;
		this.min = min;
		this.sec = sec;
		this.setByCalendar = false;
	}
	
	/**
	 * The constructor of DateWrapper class
	 * @param year	The year element
	 * @param month	The month element
	 * @param date	The date element
	 * @param hrs	The hour element
	 * @param min	The minute element
	 */
	public DateWrapper(int year, int month, int date, int hrs, int min) {
		this(year,month,date,hrs,min,0);
	}
	
	/**
	 * The constructor of DateWrapper class
	 * @param c	The calendar used to set date
	 */
	public DateWrapper(Calendar c){
		this(c.get(Calendar.YEAR), c.get(Calendar.MONTH),c.get(Calendar.DATE),c.get(Calendar.HOUR_OF_DAY),c.get(Calendar.MINUTE),c.get(Calendar.SECOND));
		this.setByCalendar = true;
	}
	
	/**
	 * The getter of calendar for certain time
	 * @return
	 */
	public Calendar getTime(){
		return new GregorianCalendar(this.year, this.setByCalendar?this.month:this.month-1,this.date,this.hrs,this.min,this.sec);
	}
	@Override
	public String toString(){
		StringBuilder sb = new StringBuilder();
		sb.append(this.year);
		sb.append("-");
		sb.append(this.setByCalendar? this.month+1:this.month);
		sb.append("-");
		sb.append(this.date);
		sb.append(" ");
		sb.append(this.hrs);
		sb.append(":");
		sb.append(this.sec);
		return sb.toString();
	}
}
